package com.yang.lesson04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame{

    public ImageIconDemo() {
        //获取图片的地址
        JLabel label = new JLabel("ImageIcon");
        URL url = ImageIconDemo.class.getResource("tc.jpg");

        //图像图标
        ImageIcon imageIcon = new ImageIcon(url);
        label.setIcon(imageIcon);//给标签设置图标，以imageicon这个图片
        //设置图片居中
        label.setHorizontalAlignment(SwingConstants.CENTER);


        Container container = getContentPane();
        container.add(label);

        setVisible(true);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        pack();
    }

    public static void main(String[] args) {
        new   ImageIconDemo();
    }
}